<template>
  <view class="order-page">
    <!-- 选项卡 -->
    <view class="tabs">
      <view
        v-for="(tab, idx) in tabs"
        :key="tab"
        :class="['tab', { active: currentTab === idx }]"
        @click="onTabClick(idx)"
      >
        {{ tab }}
      </view>
    </view>
    <view class="tab-underline" :style="{ left: underlineLeft }"></view>

    <!-- 订单列表 -->
    <scroll-view scroll-y class="order-list">
      <view
        class="order-card"
        v-for="order in filteredOrders"
        :key="order.id"
        @click="onOrderClick(order)"
      >
        <view class="order-info">
          <view>预约时间：{{ order.time }}</view>
          <view>预约医生：{{ order.doctor }}</view>
          <view>医院地址：{{ order.address }}</view>
        </view>
        <view class="order-num">
          <text class="num-label">预约号：</text>
          <text class="num-value">{{ order.num }}</text>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script setup lang="ts">
import { ref, computed } from "vue";

const tabs = ["全部", "待预约", "已完成"];
const currentTab = ref(0);

// 模拟订单数据
const orders = ref([
  {
    id: 1,
    time: "2022-10-20 11:30",
    doctor: "xxxxx",
    address: "xxxxxxxxxxx",
    num: 20,
    status: "全部",
  },
  {
    id: 2,
    time: "2022-10-20 11:30",
    doctor: "xxxxx",
    address: "xxxxxxxxxxx",
    num: 11,
    status: "待预约",
  },
  {
    id: 3,
    time: "2022-10-20 11:30",
    doctor: "xxxxx",
    address: "xxxxxxxxxxx",
    num: 9,
    status: "已完成",
  },
  {
    id: 4,
    time: "2022-10-20 11:30",
    doctor: "xxxxx",
    address: "xxxxxxxxxxx",
    num: 6,
    status: "全部",
  },
  {
    id: 5,
    time: "2022-10-20 11:30",
    doctor: "xxxxx",
    address: "xxxxxxxxxxx",
    num: 3,
    status: "待预约",
  },
  {
    id: 6,
    time: "2022-10-20 11:30",
    doctor: "xxxxx",
    address: "xxxxxxxxxxx",
    num: 1,
    status: "已完成",
  },
]);

const filteredOrders = computed(() => {
  if (currentTab.value === 0) return orders.value;
  return orders.value.filter((o) => o.status === tabs[currentTab.value]);
});

const onBack = () => {
  uni.navigateBack();
};
const onTabClick = (idx: number) => {
  currentTab.value = idx;
};
const onOrderClick = (order: any) => {
  uni.showToast({ title: `点击预约号：${order.num}`, icon: "none" });
};

// 选项卡下划线动画
const underlineLeft = computed(() => {
  return `${currentTab.value * 33.33}%`;
});
</script>

<style scoped>
.order-page {
  background: #fff;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.header {
  display: flex;
  align-items: center;
  height: 100rpx;
  background: #fff;
  box-shadow: 0 8rpx 24rpx rgba(25, 195, 60, 0.08);
  padding: 0 32rpx;
  position: relative;
  z-index: 2;
}
.back {
  font-size: 48rpx;
  color: #19c37c;
  font-weight: bold;
  margin-right: 24rpx;
  cursor: pointer;
}
.title {
  font-size: 36rpx;
  color: #19c37c;
  font-weight: bold;
}
.tabs {
  display: flex;
  background: #fff;
  margin-top: 8rpx;
  position: relative;
  z-index: 1;
}
.tab {
  flex: 1;
  text-align: center;
  font-size: 32rpx;
  color: #999;
  font-weight: bold;
  padding: 24rpx 0 16rpx 0;
  position: relative;
  cursor: pointer;
}
.tab.active {
  color: #19c37c;
}
.tab-underline {
  position: absolute;
  top: 98rpx;
  left: 0;
  width: 33.33%;
  height: 6rpx;
  background: #19c37c;
  border-radius: 3rpx;
  transition: left 0.2s;
  z-index: 2;
}
.order-list {
  flex: 1;
  overflow-y: auto;
  padding: 24rpx 0 0 0;
}
.order-card {
  background: #fff;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 16rpx rgba(25, 195, 60, 0.12);
  border: 2rpx solid #19c37c;
  margin: 0 24rpx 32rpx 24rpx;
  padding: 32rpx 24rpx 24rpx 24rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: box-shadow 0.2s;
  cursor: pointer;
}
.order-card:active {
  box-shadow: 0 2rpx 8rpx rgba(25, 195, 60, 0.18);
}
.order-info {
  flex: 1;
  font-size: 26rpx;
  color: #666;
  line-height: 2.2;
}
.order-num {
  font-size: 36rpx;
  font-weight: bold;
  color: #888;
  margin-left: 32rpx;
  display: flex;
  align-items: center;
}
.num-label {
  font-size: 30rpx;
  color: #888;
  margin-right: 8rpx;
}
.num-value {
  color: #19c37c;
  font-size: 40rpx;
  font-weight: bold;
}
</style>
